/*
 * @Author: szx
 * @Date: 2021-11-28 14:02:18
 * @LastEditTime: 2021-11-28 14:14:17
 * @Description:
 * @FilePath: \leetcode\1-99\56\56.js
 */
/**
 * @param {number[][]} intervals
 * @return {number[][]}
 */
var merge = function (intervals) {
    intervals.sort((a, b) => a[0] - b[0]);
    const res = [intervals[0]];
    tmp = intervals[0];
    for (let nums of intervals) {
        if (nums[0] > tmp[1]) res.push(nums);
        else if (nums[1] > tmp[1]) {
            res[res.length - 1][1] = nums[1];
        }
        tmp = res[res.length - 1];
    }
    return res;
};

console.table(
    merge([
        [2, 3],
        [2, 2],
        [3, 3],
        [1, 3],
        [5, 7],
        [2, 2],
        [4, 6]
    ])
);
